package com.chixing.service.impl;

import com.chixing.mapper.NotesCollectMapper;
import com.chixing.mapper.SightsCollectMapper;
import com.chixing.mapper.TravelNotesMapper;
import com.chixing.mapper.TravelSightsMapper;
import com.chixing.pojo.NotesCollect;
import com.chixing.pojo.NotesCollectExample;

import com.chixing.pojo.TravelNotes;
import com.chixing.pojo.TravelSights;
import com.chixing.service.NotesCollectionService;

import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
@Service
public class NotesCollectionServiceImpl implements NotesCollectionService {

    @Autowired
    private NotesCollectMapper notesCollectMapper;
    @Autowired
    private TravelNotesMapper travelNotesMapper;
    @Override
    public ServerResponse getNotesbycustId(Integer custId) {
        NotesCollectExample notesCollectExample=new NotesCollectExample();
        notesCollectExample.createCriteria().andCustIdEqualTo(custId);
        List<NotesCollect> notesCollects=notesCollectMapper.selectByExample(notesCollectExample);
        List<TravelNotes> travelNotesArrayList=new ArrayList<>();
        for(NotesCollect notesCollect :notesCollects){
            TravelNotes travelNotes=travelNotesMapper.selectByPrimaryKey(notesCollect.getTravelNotesId());
            travelNotesArrayList.add(travelNotes);
        }
        return ServerResponse.getSuccess(travelNotesArrayList);
    }

    @Override
    public ServerResponse deleteNotesbysightsId(Integer  notesCollectId) {
        NotesCollect notesCollect =  notesCollectMapper.selectByPrimaryKey(notesCollectId);
        notesCollect.setNotesCollectStatus(0);
        int rows=notesCollectMapper.updateByPrimaryKey(notesCollect);
        if(rows >0)
            return ServerResponse.deleteSuccess(rows);
        else
            return ServerResponse.deleteFail(null);
    }

    @Override
    public ServerResponse updateNotescustId(Integer custId) {
        return null;
    }
}
